package com.wqc.task;


import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.sql.Time;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

@Component
public class TimerTask {

    @Scheduled(cron = "0 29 18 * * ? ") // 间隔5秒执行
    public void task01() throws InterruptedException {
        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(sdf.format(new Date())+"----task01 定时任务开始执行-----");
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //执行具体业务逻辑----------
        int i = 0;
        /*while(true) {
            System.out.println("task01 执行业务逻辑");
            Thread.sleep(1000);
            if (i == 10) {
                break;
            }
            i++;
        }*/
        System.out.println(sdf.format(new Date())+"----task01 定时任务执行结束-----");
    }

    @Scheduled(cron = "0 29 18 * * ? ") // 间隔5秒执行
    public void task02() {
        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(sdf.format(new Date())+"----task02 定时任务开始执行-----");
        //执行具体业务逻辑----------
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(sdf.format(new Date())+"----task02 定时任务执行结束-----");
    }

}
